package com.danbay.cloud.timedtask.config;

import com.danbay.cloud.timedtask.service.XXService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author SJG
 *         2017/12/22.
 */
@Configuration
@EnableConfigurationProperties
public class TaskScheduledConfig {

    /**
     * 限制是否开启xxx任务的配置
     */
    @Value("${timedtask.xxxtask.enable:false}")
    private boolean xxxTaskEnable = false;
    @Autowired
    private XXService xxService;

    @Scheduled(cron = "${timedtask.xxxtask.cron}")
    public void xxxTask() {
        if (!xxxTaskEnable) {
            return;
        }
        xxService.test();
    }


    @Bean
    public RedisTemplate<?, ?> redisTemplate() {

        RedisTemplate<byte[], byte[]> template = new RedisTemplate<byte[], byte[]>();
        return template;
    }
}
